fix: gate OpenCode listener (port 10004) on explicit AWF_ENABLE_OPENCODE flag#2337
fix: gate OpenCode listener (port 10004) on explicit AWF_ENABLE_OPENCODE flag#2337
Conversation
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.94% | 85.95% | 📈 +0.01% |
| Statements | 85.93% | 85.93% | ➡️ +0.00% |
| Functions | 87.93% | 87.96% | 📈 +0.03% |
| Branches | 80.08% | 79.97% | 📉 -0.11% |
📁 Per-file Coverage Changes (2 files)
| File | Lines (Before → After) | Statements (Before → After) |
|---|---|---|
src/cli.ts |
58.8% → 58.8% (-0.09%) | 59.3% → 59.2% (-0.10%) |
src/docker-manager.ts |
87.4% → 87.7% (+0.29%) | 87.0% → 87.3% (+0.27%) |
Coverage comparison generated by scripts/ci/compare-coverage.ts
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR makes the OpenCode listener (api-proxy port 10004) opt-in by introducing an explicit AWF_ENABLE_OPENCODE=true gate, preventing the listener from starting (and /reflect from reporting it as configured) in workflows that don’t use OpenCode.
Changes:
- Add
enableOpenCode?: booleantoWrapperConfig, and expose it via--enable-opencode. - Inject
AWF_ENABLE_OPENCODE=trueinto the api-proxy sidecar environment only when explicitly enabled. - Gate OpenCode’s
/reflect“configured” status, startup latch expected listener count, and the listener startup block onAWF_ENABLE_OPENCODE.
Show a summary per file
| File | Description |
|---|---|
containers/api-proxy/server.js |
Adds AWF_ENABLE_OPENCODE gating for OpenCode reflect/config state, readiness latch counting, and the 10004 listener startup. |
containers/api-proxy/server.test.js |
Updates reflectEndpoints test expectations for the default-disabled OpenCode behavior. |
src/types.ts |
Introduces enableOpenCode?: boolean config flag with documentation. |
src/docker-manager.ts |
Conditionally injects AWF_ENABLE_OPENCODE=true into api-proxy env when enabled. |
src/docker-manager.test.ts |
Adds tests asserting AWF_ENABLE_OPENCODE env injection behavior. |
src/cli.ts |
Adds --enable-opencode flag and wires it into WrapperConfig. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
containers/api-proxy/server.js:1774
- The new
if (ENABLE_OPENCODE)block isn’t indented like the surrounding listener startup code, which makes it easy to misread the block structure (especially with nestedif (opencodeStartupRoute)). Re-indent the block contents to match the file’s existing style so future edits don’t accidentally introduce brace/scope bugs.
if (ENABLE_OPENCODE) {
const opencodeStartupRoute = resolveOpenCodeRoute(
OPENAI_API_KEY, ANTHROPIC_API_KEY, COPILOT_AUTH_TOKEN,
OPENAI_API_TARGET, ANTHROPIC_API_TARGET, COPILOT_API_TARGET,
OPENAI_API_BASE_PATH, ANTHROPIC_API_BASE_PATH
);
- Files reviewed: 6/6 changed files
- Comments generated: 2
| it('should report opencode as not configured when AWF_ENABLE_OPENCODE is not set', () => { | ||
| // ENABLE_OPENCODE is false at module load time (AWF_ENABLE_OPENCODE not set in test env), | ||
| // so opencode.configured must always be false regardless of other credentials. | ||
| const result = reflectEndpoints(); | ||
| const opencode = result.endpoints.find((e) => e.provider === 'opencode'); | ||
| expect(typeof opencode.configured).toBe('boolean'); | ||
| expect(opencode.configured).toBe(false); | ||
| expect(opencode.models).toBeNull(); | ||
| expect(opencode.models_url).toBeNull(); |
There was a problem hiding this comment.
This change adds coverage for the disabled-by-default case, but there’s no corresponding test asserting that setting AWF_ENABLE_OPENCODE=true at module load time flips opencode.configured to true when a credential is present. Add a test that sets the env var before importing the module (e.g., via jest.resetModules()/jest.isolateModules()), so regressions in the enable flag wiring are caught.
| enableApiProxy: options.enableApiProxy, | ||
| enableOpenCode: options.enableOpencode, | ||
| modelAliases, |
There was a problem hiding this comment.
The CLI help text says --enable-opencode requires --enable-api-proxy, but there’s no validation enforcing that relationship. If a user sets --enable-opencode without --enable-api-proxy, the flag silently has no effect (no api-proxy sidecar -> no port 10004). Add a validation/error similar to validateRateLimitFlags so misuse fails fast with a clear message.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot address the review feedback |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…-api-proxy; add AWF_ENABLE_OPENCODE=true test
Done in db88f48. Both review comments addressed:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
GitHub MCP Testing: ✅
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot the flag should also be enabled in the stdin config spec |
Done in c4b5177. Added |
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 85.94% | 85.95% | 📈 +0.01% |
| Statements | 85.93% | 85.94% | ➡️ +0.01% |
| Functions | 87.93% | 87.96% | 📈 +0.03% |
| Branches | 80.08% | 80.00% | 📉 -0.08% |
📁 Per-file Coverage Changes (3 files)
| File | Lines (Before → After) | Statements (Before → After) |
|---|---|---|
src/cli.ts |
58.8% → 58.8% (-0.09%) | 59.3% → 59.2% (-0.10%) |
src/config-file.ts |
96.8% → 96.9% (+0.04%) | 96.5% → 96.5% (+0.03%) |
src/docker-manager.ts |
87.4% → 87.7% (+0.29%) | 87.0% → 87.3% (+0.27%) |
Coverage comparison generated by scripts/ci/compare-coverage.ts
🔥 Smoke Test: Copilot BYOK — PASS
Running in BYOK offline mode ( Overall: PASS —
|
|
Smoke Test Results ✅ GitHub MCP: Last 2 merged PRs retrieved Status: PASS
|
🔥 Smoke Test Results — PASS
PR: fix: gate OpenCode listener (port 10004) on explicit AWF_ENABLE_OPENCODE flag Overall: PASS ✅
|
Chroot Version Comparison Results
Overall: ❌ Not all versions match — Python and Node.js differ between host and chroot environments.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results
Overall: FAIL — Service containers not reachable via
|
|
feat: add enableOpenCode to AwfFileConfig (stdin/file config spec) Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
The OpenCode listener started unconditionally whenever any credential was present (
OPENAI_API_KEY,ANTHROPIC_API_KEY, orCOPILOT_AUTH_TOKEN), causing misleading/reflectdiagnostics and unnecessary port exposure in workflows that don't use OpenCode (e.g. Copilot-only runs).Changes
containers/api-proxy/server.js— ReadAWF_ENABLE_OPENCODEenv var (ENABLE_OPENCODE); gateopencodeConfiguredinreflectEndpoints(), theexpectedListeners++count in the health-check latch, and the entire port-10004 listener startup block on this flag.src/types.ts— AddenableOpenCode?: booleantoWrapperConfig.src/docker-manager.ts— InjectAWF_ENABLE_OPENCODE=trueinto the api-proxy environment only whenconfig.enableOpenCodeis true.src/cli.ts— Expose--enable-opencodeflag wired toconfig.enableOpenCode. AddvalidateEnableOpenCodeFlag(following the same pattern asvalidateRateLimitFlags) so that using--enable-opencodewithout--enable-api-proxyexits immediately with a clear error message.src/config-file.ts— AddenableOpenCode?: booleantoAwfFileConfig.apiProxyso the flag can be set via config file or stdin. Validated as a boolean and mapped to theenableOpencodeCLI option inmapAwfFileConfigToCliOptions.Behaviour
Before: OpenCode listener started whenever any of
OPENAI_API_KEY | ANTHROPIC_API_KEY | COPILOT_AUTH_TOKENwas set.After: OpenCode listener only starts when
AWF_ENABLE_OPENCODE=true, mirroring the explicit-key pattern already used by Gemini. Using--enable-opencodewithout--enable-api-proxyis now a hard error. The flag is also configurable via the AWF config file/stdin spec underapiProxy.enableOpenCode.